import json,os

import psutil


def sftpGetWindows(dir):
    newDirList = ["<li class='ftpBack' style='left: 5%;position: relative;color: #FFF;' onclick='backDirWin(this)'>back</li>","<li class='sftpWinRoot'>" + dir + "</li>"]

    print(dir)

    if dir == "": #获取所有盘符
        thisList = psutil.disk_partitions()
        for list in thisList:
            newDirList = newDirList + ["<li class='sftpLinuxP' onclick='intoDirWin(this)'>" + json.dumps(list,ensure_ascii=False).split(",")[0].split("[")[1] + "</li>"]
    else:
        thisList = os.listdir(dir)
        for list in thisList:
            if os.path.isdir(dir + list): # 需绝对目录
                newDirList = newDirList + ["<li class='sftpLinuxP' onclick='intoDirWin(this)'>" + list + "</li>"]
            else:
                newDirList = newDirList + ["<li class='sftpLinuxC' onclick='uploadFile(this)'>" + list + "</li>"]

    return json.dumps(newDirList,ensure_ascii=False)
